package com.iwhalecloud.bss.kite.cucc.common.exception;

import com.ztesoft.bss.common.exception.BssException;
import com.ztesoft.bss.common.util.I18nUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;

import java.util.Date;

@SuppressWarnings("serial")
@ResponseStatus(code=HttpStatus.SEE_OTHER, reason="数据校验异常")
public class DataValidException extends BssException {
	
	/**
     * The Date.
     */
    private Date date;

    /**
     * The Log module.
     */
    private String logModule;
    
    /**
     * The Fail code.
     */
    private String failCode;
    
    /**
     * The Fail msg.
     */
    private String failMsg;

	/**
     * Instantiates a new Bss exception.
     *
     * @param logModule the log module
     * @param failCode  the fail code
     * @param failMsg   the fail msg
     */
    public DataValidException(String logModule, String failCode, String failMsg) {
        super(failMsg);
        this.logModule = logModule;
        this.failCode = failCode;
        this.failMsg = getFailMsg(failMsg);
        date = new Date(System.currentTimeMillis());
    }

    private String getFailMsg(String codeFailMsg) {
        String i18nUtilFailMsg = I18nUtil.getMessageWithoutLog(codeFailMsg);
        i18nUtilFailMsg = StringUtils.isEmpty(i18nUtilFailMsg) ? codeFailMsg : i18nUtilFailMsg;
        return i18nUtilFailMsg;
    }
}
